<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 首页接口
 */
class News extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

   public function get_list(){
       $categoryId = $this->request->get('category_id');
       $list = \app\api\model\News::where('status',1)
           ->where(function ($q) use ($categoryId){
               if($categoryId){
                   $q->where('category_id',$categoryId);
               }
           })
           ->order('weigh','desc')
           ->field('title,describe,cover,id')
           ->paginate();
       foreach ($list as &$value){
           $value['cover']=$value['cover']?$this->request->domain().$value['cover']:'';
       }
       $res = ['total' => $list->total(), 'rows' => $list->items()];
       $this->success('成功',$res);
   }
   public function detail(){
       $newsId = $this->request->get('id');
       $res = \app\api\model\News::where('status',1)->where('id',$newsId)->field('title,describe,content,mobile,author,createtime')->find();
       $res['createtime']=date('Y-m-d H:i:s',$res['createtime']);
       $this->success('成功',$res);
   }

   public  function material_evaluation(){

       $categoryId = $this->request->get('category_id');
       $list = \app\api\model\MaterialEvaluation::where('status',1)
           ->where(function ($q) use ($categoryId){
               if($categoryId){
                   $q->where('category_id',$categoryId);
               }
           })
           ->order('weigh','desc')
           ->field('title,image,describe')
           ->select();
       foreach ($list as &$value){
           $value['image']=$value['image']?$this->request->domain().$value['image']:'';
       }
       $this->success('成功',['list' => $list]);
   }
}
